package com.gadgets.framework.sysParam.init;

import com.gadgets.framework.common.util.CacheUtils;
import com.gadgets.framework.start.AbsCacheInitLoaderProcess;
import com.gadgets.framework.sysParam.dto.SysParamQueryResultDTO;
import com.gadgets.framework.sysParam.repository.ISysParamRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2021-07-29
 * @moduel gadgets
 *
 */
@Component
public class SysParamStartIntiLoader extends AbsCacheInitLoaderProcess {

    @Autowired
    private ISysParamRepository sysParamRepository;
    @Autowired
    CacheUtils cacheUtils;

    public SysParamStartIntiLoader() {
        super("1");
    }

    /**
     * 初始化执行方法
     */
    @Override
    public void initLoad() {
        logger.info("开始初始化加载系统缓存");
        // 查询系统参数
        List<SysParamQueryResultDTO> resultDTOList = sysParamRepository.selectSysParamByConditionAndPagination(null);
        // 将系统参数加入缓存
        if(null!=resultDTOList && resultDTOList.size()>0){
            for (SysParamQueryResultDTO sysParam : resultDTOList) {
                logger.debug("参数{}加入缓存，参数值{}",sysParam.getParamCode(),sysParam.getParamValue());
                cacheUtils.putSysParamCache(sysParam.getParamCode(),sysParam.getParamValue());
            }
        }
        logger.info("初始化加载系统缓存完成");
    }

}
